﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OASys.Web.Areas.ModuleWF.Models;
using Project.Common;
using OASys.Biz.BizAccess;
using Project.Web.Base;
using Project.Web.Base.Utility;

namespace OASys.Web.Areas.ModuleWF.Controllers
{
	public class WorkFlowStepController : BaseController
	{
		private BizWFFlowSteps bizWFFlowSteps;
		//
		// GET: /ModuleWF/WorkFlowStep/

		public ActionResult Index(ModelWorkFlowStepIndex model)
		{
			model.RetriveData();
			return View(model);
		}

		public ActionResult Create(ModelWorkFlowStepCreate model)
		{
			return View(model);
		}

		[HttpPost]
		public ActionResult Create(ModelWorkFlowStepCreate model,FormCollection collection)
		{
			try
			{
				model.Save();
				var instance = DialogOption.GetDefaultInstance();
				instance.Index = 2;
				return Content(WebTools.ScriptRefreshDialog(1) + WebTools.ScriptCloseDialog(instance));
			}
			catch
			{
				Error = "操作失败";
				ViewBag.PageState = PageState;
				return View(model);
			}
		}

		public ActionResult Edit(ModelWorkFlowStepEdit model)
		{
			model.RetriveData();
			return View(model);
		}

		[HttpPost]
		public ActionResult Edit(ModelWorkFlowStepEdit model,FormCollection collection)
		{
			try
			{
				model.Save();
				var instance = DialogOption.GetDefaultInstance();
				instance.Index = 2;
				return Content(WebTools.ScriptRefreshDialog(1) + WebTools.ScriptCloseDialog(instance));
			}
			catch
			{
				Error = "操作失败";
				ViewBag.PageState = PageState;
				return View(model);
			}
		}

		public ActionResult Delete(ModelWorkFlowStepDelete model)
		{
			JsonResult jsresult = new JsonResult();
			jsresult.ContentType = Consts.CONTENT_TYPE;
			try
			{
				model.Delete();
				jsresult.Data = new { result = string.Empty };
			}
			catch
			{
				jsresult.Data = new { result = "操作失败" };
			}
			return jsresult;
		}

	}
}
